// 初始化Form1
function doOnFormInit1(){
 
	if(typeof editForm1!='object') {
		$func.alert('初始化详细信息页面失败', 'red');
		return ;
	}
	/*var status = editForm1.getCombo('status');
	status.addOption(parent.statusComboData);
	status.setComboValue('');
	status.readonly(true);*/

	$(editForm1.getInput("dictCode")).attr("maxlength",50);
	$(editForm1.getInput("dictName")).attr("maxlength",50);
	$(editForm1.getInput("sortNum")).attr("maxlength",9);
	$(editForm1.getInput("extValue")).attr("maxlength",200);
	$(editForm1.getInput("remark")).attr("maxlength",100);

	if(edit_type=='add' && parent.oneHosDictGroupInfo && parent.oneHosDictGroupInfo.group_code){
		//已选择分组
		editForm1.setItemValue("groupCode",escape2Html(parent.oneHosDictGroupInfo.group_code));
		editForm1.setItemValue("groupName",escape2Html(parent.oneHosDictGroupInfo.group_name));
	}

	if(edit_type=='add'){
		editForm1.setItemValue("id",parent.rondomNum);
	}

	if(edit_type!='edit') return;
 	if (!parent.oneHosDictInfo||!parent.oneHosDictInfo.id) return;
	editForm1.setItemValue("id",escape2Html(parent.oneHosDictInfo.id));
	editForm1.setItemValue("groupCode",escape2Html(parent.oneHosDictInfo.group_code));
	editForm1.setItemValue("groupName",escape2Html(parent.oneHosDictInfo.group_name));
	editForm1.setItemValue("dictName",escape2Html(parent.oneHosDictInfo.dict_name));
	editForm1.setItemValue("dictCode",escape2Html(parent.oneHosDictInfo.dict_code));
	// editForm1.setItemValue("status",parent.oneHosDictInfo.status);
	editForm1.setItemValue("sortNum",escape2Html(parent.oneHosDictInfo.sort_num));
	editForm1.setItemValue("extValue",escape2Html(parent.oneHosDictInfo.ext_value));
	editForm1.setItemValue("remark",escape2Html(parent.oneHosDictInfo.remark));
	/*editForm1.setReadonly('groupCode', true);
	editForm1.setReadonly('groupName', true);*/
}
//初始化按钮form
function doOnButtonForm(){
	if (typeof(buttonForm) == "object"){
		buttonForm.attachEvent("onButtonClick", function(name, command) {
			switch(command) {
				case 'save':doSave();break;
				case 'cancle':doCancle();break;
			}
		});
	}
}

//校验新增/编辑form表单
function checkForm(){
	var groupCode = $.trim(editForm1.getItemValue("groupCode"));
	if(groupCode.length==0){
		$func.alert('字典编码不能为空', 'red');
		return false;
	}
	var groupName = $.trim(editForm1.getItemValue("groupName"));
	if(groupName.length==0){
		$func.alert('字典名称不能为空', 'red');
		return false;
	}
	var dictName = $.trim(editForm1.getItemValue("dictName"));
	if(dictName.length==0){
		$func.alert('请输入枚举名称', 'red');
		return false;
	}
	var dictCode = $.trim(editForm1.getItemValue("dictCode"));
	if(dictCode.length==0){
		$func.alert('请输入枚举编码', 'red');
		return false;
	}
	var sortNum = $.trim(editForm1.getItemValue("sortNum"));
	if(sortNum.length!=0){
		var pattern =  /^[0-9]*[1-9][0-9]*$/;
		if(!pattern.test(sortNum)){
			$func.alert('排序只能为正整数', 'red');
			return false;
		}
	}
	/*var status = $.trim(editForm1.getItemValue("status"));
	if(status.length==0){
		$func.alert('请选择状态', 'red');
		return false;
	}*/
	return true;
}
//保存动作
function doSave(){
	if(!checkForm())return;
	// editForm1.removeItem("name");
	// editForm1.setItemValue("cateTypeValue",editForm1.getCombo("cateType").getComboText());
 	var formData = JSON.stringify(editForm1.getFormData());
 	var url=basePath+'dict/addSysDict';
 	if(edit_type=='edit') url=basePath+'dict/editSysDict';
	$.ajax({
        url: url,
        type: 'post',
        dataType: 'json',
        contentType:"application/json",
        data:formData,
        success: function (back) {
        	if(!back||!back.result){
        		$func.alert(back.message?back.message:'保存出错', "red");
        		return;
        	}
        	$func.alert("成功！", "green");
        	parent.doRefreshDict();
        	doCancle();
        }
    });
}
//取消动作
function doCancle(){
	parent.editHosDictWin.close();
}
 